package cn.fintecher.gis.web;

import cn.fintecher.gis.annotation.CurrentOperator;
import cn.fintecher.gis.entity.ReportInfo;
import cn.fintecher.gis.model.request.ReportInfoRequest;
import cn.fintecher.gis.model.session.SessionModel;
import cn.fintecher.gis.service.ReportInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @Auther: xiaqun
 * @Description: 报地信息相关接口
 * @Date: 17:10 2019/4/29
 */

@RestController
@RequestMapping("/api/reportInfoController")
@Api(value = "reportInfoController", description = "报地信息相关接口")
public class ReportInfoController extends BaseController {
    @Autowired
    private ReportInfoService reportInfoService;

    /**
     * 新增报地信息
     */
    @PostMapping("/addReportInfo")
    @ApiOperation(value = "新增报地信息", notes = "新增报地信息")
    public ResponseEntity<Void> addReportInfo(@RequestBody ReportInfoRequest request,
                                              @ApiIgnore @CurrentOperator SessionModel operator) throws Exception {
        log.debug("REST request to addReportInfo,{}", request);
        reportInfoService.addReportInfo(request, operator);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/getReportByName")
    @ApiOperation(value = "根据名称查询报地信息", notes = "根据名称查询报地信息")
    public ResponseEntity<List<ReportInfo>> getReportByName(@RequestParam("name") String name) {
        List<ReportInfo> list = reportInfoService.getReportInfoByName(name);
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getReportById/{id}")
    @ApiOperation(value = "根据报地id查询报地信息", notes = "根据报地id查询报地信息")
    public ResponseEntity<ReportInfo> getReportById(@PathVariable String id) {
        ReportInfo reportInfo = reportInfoService.getReportInfoById(id);
        return ResponseEntity.ok().body(reportInfo);
    }
}
